package com.zhentao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.dao.UserMapper;
import com.zhentao.entity.center.login.User;
import com.zhentao.service.UserService;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Override
    public String add(User user) {
        user.setCreateTime(new Date());
        this.baseMapper.insert(user);
        return "添加成功";
    }

    @Override
    public String del(Integer id) {
        User user = this.baseMapper.selectById(id);
        this.baseMapper.deleteById(user);
        return "删除成功";
    }

    @Override
    public User sel(String username) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("username", username);
        return this.baseMapper.selectOne(wrapper);
    }
}
